package com.wf.day_0611.test1;

import java.util.concurrent.FutureTask;

/**
 * @author mpk
 * @since 2024/6/11 17:19:12
 */
public class Demo {
    public static void main(String[] args) {


        //继承thread
        MyThread myThread = new MyThread("继承thread");
        myThread.start();

        //实现Runnable
        MyRunnable myRunnable = new MyRunnable();
        Thread mRunnable = new Thread(myRunnable, "实现Runnable");
        Thread mRunnable1 = new Thread(() ->
        {
            for (int i = 0; i < 30; i++) {
                System.out.println(Thread.currentThread().getName() + "-->" + i);
            }
        }
                , "实现Runnable"
        );
        mRunnable.start();

        //实现Callable
        MyCallable myCallable = new MyCallable();
        FutureTask<Integer> task = new FutureTask<>(myCallable);
        Thread mCallable = new Thread(task, "实现Callable");
        mCallable.start();
        try {
            System.out.println(task.get());
        } catch (Exception e) {
            e.printStackTrace();
        }
        //实现Callable
        new Thread(new FutureTask<>(() ->
        {
            int sum = 0;
            for (int i = 0; i < 30; i++) {
                sum += i;
                System.out.println(Thread.currentThread().getName() + "-->" + i);
            }
            return sum;
        }), "实现Callable01").start();
        try {
            System.out.println(task.get());
        } catch (Exception e) {
            e.printStackTrace();
        }


    }


}
